package cn.lf.android.lawfirm.changeapproval.controller;


import android.content.Context;

import com.alibaba.fastjson.JSON;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import cn.lf.android.lawfirm.AppConfig;
import cn.lf.android.lawfirm.BaseController;
import cn.lf.android.lawfirm.http.manager.EBCallback;
import cn.lf.android.lawfirm.http.manager.MyOkHttpClient;
import cn.lf.android.lawfirm.undertake.approval.modle.LawyerFeeInfo;
import cn.lf.android.lawfirm.utils.DebugLog;
import cn.lf.android.lawfirm.utils.SPUtil;

public class ChangeLawyerFeeInfoController extends BaseController {
    ChangeFeeInfoCallback mChangeFeeInfoCallback;
    ChangeBeforeFeeInfoCallback mChangeBeforeFeeInfoCallback;
    private Context context;

    public ChangeLawyerFeeInfoController(ChangeFeeInfoCallback callback, Context context) {
        this.mChangeFeeInfoCallback = callback;
        this.context = context;
    }

    public ChangeLawyerFeeInfoController(ChangeBeforeFeeInfoCallback callback, Context context) {
        this.mChangeBeforeFeeInfoCallback = callback;
//        this.mChangeBeforeFeeListCallback = callback2;
        this.context = context;
    }

    /**
     * @param relationID
     */
    public void onFeeInfo(String relationID) {
        showProgressDia(context);
        Map<String, String> params = new HashMap<String, String>();
        SPUtil spUtil = new SPUtil(context);
        params.put("relationID", relationID);
        params.put("Authorization", spUtil.getAccessToken());
        DebugLog.e("caseId=666=" + relationID);
        DebugLog.e("Authorization=666=" + spUtil.getAccessToken());
        new MyOkHttpClient().doGet(AppConfig.LSCaseApproveRecordList_CaseCharge_CaseCharge, params,
                new EBCallback() {
                    @Override
                    public void onEBResponse(String response) {
                        DebugLog.e("律师费==" + response);
                        JSONObject myJsonObject;
                        JSONObject responsObject;
                        Boolean isSuc;
                        String arraylist;
                        try {
                            myJsonObject = new JSONObject(response);
                            isSuc = myJsonObject.getBoolean("isSuc");
                            if (isSuc) {
                                responsObject = myJsonObject.getJSONObject("responsObject");
                                LawyerFeeInfo bean = JSON.parseObject(responsObject.toString(), LawyerFeeInfo.class);
                                mChangeFeeInfoCallback.onChangeFeeInfoSuccessed(bean);
                            } else {
                                mChangeFeeInfoCallback
                                        .onChangeFeeInfoFailed();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        dismissProgressDia();
                    }

                    @Override
                    public void onEBError(String errorMsg) {
                        mChangeFeeInfoCallback.onChangeFeeInfoFailed();
                        dismissProgressDia();
                    }
                }, "Authorization", spUtil.getAccessToken());
    }

    /**
     * 变更前信息
     */
    public void onBeforeFeeInfo(String SID) {
        Map<String, String> params = new HashMap<String, String>();
        SPUtil spUtil = new SPUtil(context);
        params.put("SID", SID);
        new MyOkHttpClient().doGet(AppConfig.LSCaseApproveRecordList_CaseCharge_HistoryChargeInfo, params,
                new EBCallback() {
                    @Override
                    public void onEBResponse(String response) {
                        DebugLog.e("变更前信息==" + response);
                        JSONObject myJsonObject;
                        JSONObject responsObject;
                        Boolean isSuc;
                        String arraylist;
                        try {
                            myJsonObject = new JSONObject(response);
                            isSuc = myJsonObject.getBoolean("isSuc");
                            if (isSuc) {
                                responsObject = myJsonObject.getJSONObject("responsObject");
                                LawyerFeeInfo bean = JSON.parseObject(responsObject.toString(), LawyerFeeInfo.class);
                                mChangeBeforeFeeInfoCallback.onChangeBeforeFeeInfoSuccessed(bean);
                            } else {
                                mChangeBeforeFeeInfoCallback
                                        .onChangeBeforeFeeInfoFailed();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onEBError(String errorMsg) {
                        mChangeBeforeFeeInfoCallback.onChangeBeforeFeeInfoFailed();
                    }
                }, "Authorization", spUtil.getAccessToken());
    }


//    /**
//     * 变更前集合
//     */
//    public void onBeforeFeeList(String caseId) {
//        showProgressDia(context);
//        Map<String, String> params = new HashMap<String, String>();
//        SPUtil spUtil = new SPUtil(context);
//        params.put("caseId", caseId);
//        new MyOkHttpClient().doGet(AppConfig.LSCaseApproveRecordList_CaseCharge_History, params,
//                new EBCallback() {
//                    @Override
//                    public void onEBResponse(String response) {
//                        DebugLog.e("变更前集合==" + response);
//                        JSONObject myJsonObject;
//                        Boolean isSuc;
//                        String arraylist;
//                        try {
//                            myJsonObject = new JSONObject(response);
//                            isSuc = myJsonObject.getBoolean("isSuc");
//                            if (isSuc) {
//                                arraylist = myJsonObject.getJSONArray("responsObject")
//                                        .toString();
//                                List<ChangeFee> beans = JsonBeans
//                                        .getJsonList(
//                                                arraylist,
//                                                new TypeToken<List<ChangeFee>>() {
//                                                });
//                                mChangeBeforeFeeListCallback.onChangeBeforeFeeListSuccessed(beans);
//                            } else {
//                                mChangeBeforeFeeListCallback
//                                        .onChangeBeforeFeeListFailed();
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                        dismissProgressDia();
//                    }
//
//                    @Override
//                    public void onEBError(String errorMsg) {
//                        mChangeBeforeFeeListCallback.onChangeBeforeFeeListFailed();
//                        dismissProgressDia();
//                    }
//                }, "Authorization", spUtil.getAccessToken());
//    }


    public interface ChangeFeeInfoCallback {
        public void onChangeFeeInfoSuccessed(LawyerFeeInfo beans);

        public void onChangeFeeInfoFailed();

    }

    public interface ChangeBeforeFeeInfoCallback {
        public void onChangeBeforeFeeInfoSuccessed(LawyerFeeInfo beans);

        public void onChangeBeforeFeeInfoFailed();

    }
}
